\section{music::file\_\-streamer Class Reference}
\label{classmusic_1_1file__streamer}\index{music::file_streamer@{music::file\_\-streamer}}
This class loggs the played titles.  


{\tt \#include $<$file\_\-streamer.h$>$}

\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
\bf{file\_\-streamer} (const string \&file)
\begin{CompactList}\small\item\em \doxyref{file\_\-streamer}{p.}{classmusic_1_1file__streamer} creates a \doxyref{file\_\-streamer}{p.}{classmusic_1_1file__streamer} object. \item\end{CompactList}\item 
\bf{$\sim$file\_\-streamer} ()\label{classmusic_1_1file__streamer_6a88d9f677b4898079ca367e20f93509}

\item 
void \bf{append\_\-title} (boost::shared\_\-ptr$<$ \bf{model::title} $>$ title)
\begin{CompactList}\small\item\em append\_\-title appends a title, which was played, to the file. \item\end{CompactList}\item 
list$<$ boost::shared\_\-ptr$<$ \bf{model::title} $>$ $>$ \bf{read\_\-file} ()
\begin{CompactList}\small\item\em read\_\-file reads all the played titles from the file \item\end{CompactList}\item 
list$<$ string $>$ \bf{list\_\-files} ()
\begin{CompactList}\small\item\em list\_\-files lists all available files. \item\end{CompactList}\item 
void \bf{create\_\-file} (const string \&name)
\begin{CompactList}\small\item\em create\_\-file creates a new file \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
This class loggs the played titles. 



Definition at line 39 of file file\_\-streamer.h.

\subsection{Constructor \& Destructor Documentation}
\index{music::file_streamer@{music::file\_\-streamer}!file_streamer@{file\_\-streamer}}
\index{file_streamer@{file\_\-streamer}!music::file_streamer@{music::file\_\-streamer}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}music::file\_\-streamer::file\_\-streamer (const string \& {\em file})\hspace{0.3cm}{\tt  [inline]}}\label{classmusic_1_1file__streamer_397573e4bfa924ea73ae0ce579d8cd78}


\doxyref{file\_\-streamer}{p.}{classmusic_1_1file__streamer} creates a \doxyref{file\_\-streamer}{p.}{classmusic_1_1file__streamer} object. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em file}]is the file which should be opened. Usually this is `client\_\-name`.txt \end{description}
\end{Desc}


Definition at line 47 of file file\_\-streamer.h.

\begin{Code}\begin{verbatim}48                 :_file(file) { create_file(file); } 
\end{verbatim}\end{Code}




\subsection{Member Function Documentation}
\index{music::file_streamer@{music::file\_\-streamer}!append_title@{append\_\-title}}
\index{append_title@{append\_\-title}!music::file_streamer@{music::file\_\-streamer}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void music::file\_\-streamer::append\_\-title (boost::shared\_\-ptr$<$ \bf{model::title} $>$ {\em title})}\label{classmusic_1_1file__streamer_035e28684fc5222a5488f5d409356533}


append\_\-title appends a title, which was played, to the file. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em title}]is a shared\_\-ptr to a title \end{description}
\end{Desc}


Definition at line 6 of file file\_\-streamer.cpp.

\begin{Code}\begin{verbatim}7 {
8         ofstream ofs(_file.c_str(), ofstream::app | ofstream::out);
9         string title_str = title->get_title();
10         int tmp = 0;
11         while(string::npos != (tmp = title_str.find_first_of(" ", tmp))) {
12                 title_str.replace(tmp, 1, "%20");
13         }
14         ofs << title_str << " " << title->get_filename() << " "  
15                 << title->get_duration() << endl;
16         ofs.close();
17 }
\end{verbatim}\end{Code}


\index{music::file_streamer@{music::file\_\-streamer}!create_file@{create\_\-file}}
\index{create_file@{create\_\-file}!music::file_streamer@{music::file\_\-streamer}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void music::file\_\-streamer::create\_\-file (const string \& {\em name})}\label{classmusic_1_1file__streamer_cb73b1c9f481c5d353607ede513fb15c}


create\_\-file creates a new file 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]is the name of the new file \end{description}
\end{Desc}


Definition at line 75 of file file\_\-streamer.cpp.

\begin{Code}\begin{verbatim}76 {
77         list<string> files = list_files();
78         bool found = false;
79         for(list<string>::iterator i = files.begin(); i != files.end(); ++i) {
80                 if((*i) == name) {
81                         found = true;
82                         break;
83                 }
84         }
85         if(found) {
86                 return;
87         }
88 
89         ofstream ofs("index.txt", ofstream::app | ofstream::out);
90         ofs << name << endl;
91 }
\end{verbatim}\end{Code}


\index{music::file_streamer@{music::file\_\-streamer}!list_files@{list\_\-files}}
\index{list_files@{list\_\-files}!music::file_streamer@{music::file\_\-streamer}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}list$<$ string $>$ music::file\_\-streamer::list\_\-files ()}\label{classmusic_1_1file__streamer_b8aa676dc66acddf173be3caf2776fe5}


list\_\-files lists all available files. 

\begin{Desc}
\item[Returns:]a list of strings which stores the filenames (e.g. client1.txt, client2.txt, ...) is returned. \end{Desc}


Definition at line 54 of file file\_\-streamer.cpp.

\begin{Code}\begin{verbatim}55 {
56         ifstream ifs("index.txt");
57         string line;
58         stringstream stream;
59         string file;
60         list<string> files;
61         while(ifs.good()) {
62                 getline(ifs, line);
63                 stream.str("");
64                 stream.clear();
65                 stream.str(line);
66                 stream >> file;
67                 files.push_back(file);
68         }
69         if(files.size() > 0) {
70                 files.pop_back(); // delete last line because of \n
71         }
72         return files;
73 }
\end{verbatim}\end{Code}


\index{music::file_streamer@{music::file\_\-streamer}!read_file@{read\_\-file}}
\index{read_file@{read\_\-file}!music::file_streamer@{music::file\_\-streamer}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}list$<$ boost::shared\_\-ptr$<$ \bf{model::title} $>$ $>$ music::file\_\-streamer::read\_\-file ()}\label{classmusic_1_1file__streamer_285cbca01ac3568c91afbd779b0d5bf0}


read\_\-file reads all the played titles from the file 

\begin{Desc}
\item[Returns:]a list of shared\_\-ptrs to titles. \end{Desc}


Definition at line 19 of file file\_\-streamer.cpp.

\begin{Code}\begin{verbatim}20 {
21         ifstream ifs(_file.c_str());
22         list<boost::shared_ptr<model::title> > rtrn;
23         string line;
24         string name;
25         string file;
26         int dur;
27         stringstream stream;
28         while(ifs.good()) {
29                 getline(ifs, line);
30                 stream.str("");
31                 stream.clear();
32                 stream.str(line);
33                 stream >> name >> file >> dur;
34 
35                 int tmp = 0;
36                 while(string::npos != 
37                       (tmp = name.find_first_of("%20", tmp))) {
38                         name.replace(tmp, 3, " ");
39                 }
40                 boost::shared_ptr<model::title> ptr(
41                         new model::title(name, dur));
42                 ptr->set_filename(file);
43                 rtrn.push_back(ptr);
44                 name = file = "";
45                 dur = 0;
46         }
47         if(rtrn.size() > 0) {
48                 rtrn.pop_back(); // delete last line because of \n
49         }
50         ifs.close();
51         return rtrn;
52 }
\end{verbatim}\end{Code}




The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
music/file\_\-streamer.h\item 
music/file\_\-streamer.cpp\end{CompactItemize}
